<template>
  <div class="rankingContainer">
    <div class="ranking">
      <div class="offical">
        <div class="title">官方榜</div>
        <list-table
          v-for="(item, index) in officialListDetail"
          :key="index"
          :officialListDetailItem="item"
          @clickPlay="clickPlay"
        ></list-table>
      </div>
      <div class="global">
        <div class="title">全球榜</div>
        <list-card :listCardData="globalList"></list-card>
      </div>
    </div>
  </div>
</template>

<script>
import ListTable from "../../../components/listTable/ListTable.vue";
import ListCard from "../../../components/listCard/ListCard.vue";
export default {
  name: "MyRanking",
  components: {
    ListTable,
    ListCard,
  },
  data() {
    return {
      // 榜单
      officialList: [],
      globalList: [],
      officialListDetail: [],
    };
  },
  async created() {
    await this.getAllRankings();
    this.officialList.forEach((item) => {
      this.getMusicListDetail(item.id);
    });
  },
  methods: {
    // 获取所有榜单
    async getAllRankings() {
      const { data: res } = await this.$http("toplist");
      this.officialList = res.list.slice(0, 4);
      this.globalList = res.list.slice(4);
    },
    // 根据传来的id查询歌单
    async getMusicListDetail(id) {
      // console.log(id);
      let { data: res } = await this.$http("playlist/detail", {
        params: { id },
      });
      res = res.playlist;
      this.officialListDetail.push(res);
    },
    // 点击table歌曲播放音乐
    clickPlay(id) {
      // console.log(id);
      this.$store.commit("updateMusicId", id);
      // 如果歌单发生变化则更新歌单
      if (this.officialList === this.$store.state.musicListId) {
      }
    },
  },
};
</script>

<style lang="less" scoped>
.offical {
  width: 80%;
  margin: 0 auto;
}
.title {
  width: 100%;
  line-height: 50px;
  color: #666666;
  font-size: 20px;
  margin-left: 30px;
}
</style>